package cn.new7as.cas5s.ui.record;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import java.util.List;

import cn.new7as.cas5s.R;
import cn.new7as.cas5s.ui.easy.netapi.IssueTypeApi;

public class IssuAdapter extends BaseAdapter {

    private List<IssueTypeApi.IssData> list;
    private SendTypeActivity context;


    public IssuAdapter(List<IssueTypeApi.IssData> list, SendTypeActivity context) {
        super();

        this.context = context;
        this.list = list;

    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }


    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        ViewHolder viewHolder = null;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.layout_gride_issu, parent, false);
            viewHolder = new ViewHolder();
            viewHolder.issuname = (TextView) convertView.findViewById(R.id.issuname);
            viewHolder.apply = (ImageView) convertView.findViewById(R.id.apply);
            viewHolder.itemchek = (RelativeLayout) convertView.findViewById(R.id.itemchek);


            convertView.setTag(viewHolder);

        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }


        IssueTypeApi.IssData dataBean = list.get(position);
        viewHolder.issuname.setText(dataBean.type);
        if (dataBean.isok)
            viewHolder.apply.setBackgroundResource(R.mipmap.choosetext);
        else
            viewHolder.apply.setBackgroundResource(R.mipmap.nochoosetext);
        viewHolder.itemchek.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                for (int i = 0; i < list.size(); i++) {
                    list.get(i).isok = false;
                }
                list.get(position).isok = true;
                context.setchoose(position, list.get(position).mulGopfNwomn);
                notifyDataSetChanged();
            }
        });
        return convertView;
    }

    static class ViewHolder {
        TextView issuname;
        RelativeLayout itemchek;
        ImageView apply;

    }
}
